<?php
namespace app\oa\controller;

use \app\oa\controller\Role as RoleController;
use app\oa\ext\Core;
use app\oa\ext\Role;
use app\oa\ext\UserStatus;
use app\oa\model\Task;
use think\Request;

class Employee extends RoleController {


    public function createTask(Request $request, $tn) {
        // 检测
        if(empty($request->file("file"))) {
            $this->error("没有文件");
        }

        // 创建任务
        $task = new Task();
        $task['name'] = $tn;
        $task['employee_id'] = UserStatus::getLoginID();
        $task['department_id'] = UserStatus::getDepartmentID();
        $task['status'] = 2;
        if(!$task->save()) {
            $this->error("创建任务失败");
        }
        // 上传文件
        $core = new Core($request);
        $core->upload($request, $task['id']);

    }

    public function index() {
        $tasks = Task::all(['status'=>10]);
        $this->assign("tasks", $tasks);
        return $this->fetch("employee/index");
    }

    public function alterTask(Request $request, $id) {
        $core = new Core($request);
        $core->checkStatus($id, "10");
        $core->upload($request, $id);

    }
    public function commit($id) {
        $task = Task::get($id);
        $task['status'] = 2;
        if($task->save()) {
            $this->success("操作成功");
        }else {
            $this->error("操作失败");
        }
    }

    protected function getRole()
    {
        return [Role::Employee];
    }
}